

jQuery(function ($) {
    //搜索关键字请求接口渲染页面数据
    var keyword = decodeURIComponent(window.location.href.split('=')[1]);
    var pageOnoff =true;
    var onoff = false;
    //导航栏关键字
    if (keyword && keyword != 'undefined') {
        $('#location').append('<h1>' + '>' + keyword + '</h1>');
    }
    getList(1);
    //分页按钮
    function twbsPagination(totalPage) {
       
        Page({
			num:Math.ceil(totalPage / 20),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_b'),		//指定的元素
			callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    $('.works_show').empty();
                    getList(page - 1);
                    $('html,body').animate({scrollTop:$('#content_warp ').offset().top-80}, 500);
                }
			}
		});
    };

    function getList(page) {
        $.ajax({
            type: "GET",
            url: search_url + '/search/article',
            data: {
                keyword: keyword,
                pageNum: page,
                pageSize: 20
            },
            success: function success(res) {
                if (res.code == 200&&res.data.list.length) {
                    var data = res.data.list;
                    console.log(data)
                    var total = res.data.total;
                    if (data == 0) {
                        $('#hot ul').append('<h3>\u6CA1\u6709\u6570\u636E</h3>');
                    } else {
                        $('#hot ul').empty();
                        for (var i = 0; i <data.length; i++) {
                           var a_data = data[i];
                            $('#hot ul').append('<li class="clearfix">\n<div class="title"><a href="/article-' + a_data.id + '.html" target="_blank">'+a_data.title+'</a></div><div class="ask_list_left">\n  <div class="askBox"><span class="ask_list_title"> ' + a_data.summary + '</span><a class="full_text" href="/article-' + a_data.id + '.html" target="_blank">[全文]</a> </div>\n <div class="time_tag"><span class="ask_list_time">\u53D1\u5E03\u4E8E\uFF1A' + a_data.updateTime  + '</span></div>\n </div>\n                            </li>');
                        }
                        
                            //分页按钮
                            if(pageOnoff){
                                twbsPagination(total);
                                pageOnoff=false;
 
                            }
                        
                    }
                } else {
                    alert('网络加载失败，请稍候再试！');
                }
            }
        });
    };
});